/**
 * Copyright(c) ${copyrightYear} ${company}
 * All rights reserved.
 * Created on ${date}
 */
package ${package}.action.user;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import ${package}.BaseAction;
import ${package}.service.user.UserService;
import ${package}.vo.UserVO;
import com.opensymphony.xwork2.validator.annotations.RegexFieldValidator;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
import com.opensymphony.xwork2.validator.annotations.Validations;
import com.opensymphony.xwork2.validator.annotations.ValidatorType;

/**
 * 用户Action
 * 
 * @author ${author}
 * 
 */
@Controller
@Scope("prototype")
@ParentPackage("${artifactId}-default")
@Namespace("/userManager")
public class UserAction extends BaseAction<UserVO> {
    /**
     * 
     */
    private static final long serialVersionUID = -3717080712894187487L;
    /**
     * 用户service
     */
    @Resource
    private transient UserService userService;

    /**
     * 默认的action处理方法
     * 
     * @throws Exception
     *             所有异常
     */
    @Action("/user")
    public String execute() throws Exception {
        // TODO Auto-generated method stub
        return INPUT;
    }

    /**
     * 查询
     * 
     * @throws Exception
     *             所有异常
     */
    public String query() throws Exception {
        userService.query(context);
        return JSON;
    }
    /**
     * 登录
     * 
     * @throws Exception
     *             所有异常
     */
    public String login() throws Exception {
        userService.login(context);
        return JSON;
    }

    /**
     * 注册
     * 
     * @throws Exception
     *             所有异常
     */
    //@Validations(requiredStrings = { @RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "userVO.userEntity.username", message = "用户名必须存在") }, regexFields = { @RegexFieldValidator(type = ValidatorType.SIMPLE, fieldName = "userVO.userEntity.username", expression = "[\\w\\-]{4,12}", message = "用户名必须是4-12的字符") })
    public String register() throws Exception {
        userService.addUser(context);
        return JSON;
    }

    /**
     * 注销
     * 
     * @throws Exception
     *             所有异常
     */
    public String logout() throws Exception {
        userService.logout(context);
        return JSON;
    }

}
